package com.wrupple.muba.catalogs.client.module;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.activity.shared.Activity;
import com.google.inject.Inject;
import com.google.inject.Provider;
import com.wrupple.muba.catalogs.client.activity.BrowsingActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogEntryCreateActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogEntryImportActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogEntryReadActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogEntryUpdateActivity;
import com.wrupple.muba.catalogs.client.activity.CatalogSelectionActivity;
import com.wrupple.muba.catalogs.client.cms.service.CatalogCommandService;
import com.wrupple.muba.catalogs.client.module.CatalogModule.CatalogModuleController;
import com.wrupple.muba.common.client.activity.ForkedActivityDelegate;
import com.wrupple.muba.common.shared.ServiceBus;
import com.wrupple.muba.common.shared.State.DesktopManager;

/**
 * Controls logic and behavior of Catalog Widgets FIXME this module exist for
 * the sole pourpose of loading catalog and vegetate into the Desktop
 * 
 * @author japi
 * 
 */
public class CatalogController implements CatalogModuleController {

	/**
	 * COnfiguration for the catalog engine
	 */
	private DesktopManager desktopManager;
	private Provider<BrowsingActivity> browse;
	private Provider<CatalogEntryCreateActivity> create;
	private Provider<CatalogEntryReadActivity> read;
	private Provider<CatalogEntryUpdateActivity> update;
	private Provider<CatalogEntryImportActivity> imnport;
	private CatalogSelectionActivity select;
	private CatalogCommandService commandService;
	

	@Inject
	public CatalogController(CatalogCommandService commandService,DesktopManager desktopManager, Provider<BrowsingActivity> browse,
			Provider<CatalogEntryCreateActivity> create, Provider<CatalogEntryReadActivity> read, Provider<CatalogEntryUpdateActivity> update,
			CatalogSelectionActivity select, Provider<CatalogEntryImportActivity> imnport) {
		super();
		this.commandService=commandService;
		this.desktopManager = desktopManager;
		this.browse = browse;
		this.create = create;
		this.read = read;
		this.update = update;
		this.select = select;
		this.imnport = imnport;
	}

	@Override
	public void initialize() {

	}

	@Override
	public Map<String, Activity> getActivities() {
		Map<String, Activity> regreso = new HashMap<String, Activity>(7);

		Activity browse = new ForkedActivityDelegate(this.browse, CatalogActivity.CATALOG_ID_PARAMETER, desktopManager);

		Activity create = new ForkedActivityDelegate(this.create, CatalogActivity.CATALOG_ID_PARAMETER, desktopManager);

		Activity read = new ForkedActivityDelegate(this.read, CatalogActivity.CATALOG_ID_PARAMETER, desktopManager);

		Activity update = new ForkedActivityDelegate(this.update, CatalogActivity.CATALOG_ID_PARAMETER, desktopManager);
		
		Activity imnport = new ForkedActivityDelegate(this.imnport, CatalogActivity.CATALOG_ID_PARAMETER, desktopManager);

		regreso.put(CatalogSelectionActivity.ACTIVITY_ID, select);
		regreso.put(BrowsingActivity.ACTIVITY_ID, browse);
		regreso.put(CatalogEntryCreateActivity.ACTIVITY_ID, create);
		regreso.put(CatalogEntryReadActivity.ACTIVITY_ID, read);
		regreso.put(CatalogEntryUpdateActivity.ACTIVITY_ID, update);
		regreso.put(CatalogEntryImportActivity.ACTIVITY_ID, imnport);
		
		return regreso;
	}

	@Override
	public void registerServices(ServiceBus bus) {
		bus.add(CatalogActivity.CATALOG_ID_PARAMETER, commandService);
	}
}
